/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
    /**
     * built-in config
     * @type {Egg.EggAppConfig}
     **/
    const config = exports = {
        env: 'prod',
        rundir: '/tmp',
        logger: {
            dir: '/tmp',
        },
    };
    config.security = {
        csrf: {
            // 判断是否需要 ignore 的方法，请求上下文 context 作为第一个参数
            ignore: ctx => {
                if (ctx.request.url.indexOf() == -1) {
                    return true;
                }
                return false;
            },
        }
    }

    // use for cookie sign key, should change to your own and keep security
    config.keys = appInfo.name + '_1576384476895_3620';
    config.pathname = 'admin'
        // add your middleware config here
    config.middleware = ['auth', 'state'];
    config.ignoreUrl = [`/${config.pathname}`, `/${config.pathname}/welcome`, `/${config.pathname}/login`, `/${config.pathname}/login/logut`, `/${config.pathname}/login/captcha`, `/${config.pathname}/login/dologin`]
    config.isURl = [`/${config.pathname}/login`, `/${config.pathname}/login/logut`, `/${config.pathname}/login/captcha`, `/${config.pathname}/login/dologin`]
    config.state = { pathname: config.pathname }
    config.auth = { match: '/admin', pathname: config.pathname, ignoreUrl: config.ignoreUrl, isURl: config.isURl },
        config.view = {
            mapping: {
                '.html': 'ejs',
            },
        };
    config.sequelize = {
        dialect: 'mysql',
        host: '47.100.33.250',
        port: 3306,
        database: 'serverless',
        // 用户名
        username: 'serverless',
        // 密码
        password: 'pD3GzmGKzPwih7fG',
    };
    config.mysql = {
        // 单数据库信息配置
        client: {
            // host
            host: '47.100.33.250',
            // 端口号
            port: '3306',
            // 用户名
            user: 'serverless',
            // 密码
            password: 'pD3GzmGKzPwih7fG',
            // 数据库名
            database: 'serverless',
        },
        // 是否加载到 app 上，默认开启
        app: true,
        // 是否加载到 agent 上，默认关闭
        agent: false,
    };
    config.sequelize = {
        dialect: 'mysql',
        host: '47.100.33.250',
        port: 3306,
        // 用户名
        username: 'serverless',
        // 密码
        password: 'pD3GzmGKzPwih7fG',
        // 数据库名
        database: 'serverless',
    };

    // file上传文件
    // config.multipart = {
    //     mode: 'file',
    // };
    config.multipart = {
        fileSize: '50mb',
        mode: 'stream',
        fileExtensions: ['.xls', '.txt', '.md', '.pdf'], // 扩展几种上传的文件格式
    };

    config.cors = {
        origin: "*", // 跨任何域
        allowMethods: "GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS", // 被允许的请求方式
    };

    return {
        ...config,
    };
};